To pass value from one form to another we have to add a property in the form from which we want to send data. To set property we have to write the following code. Let us say this is form2.
publicint num
{
get
{
return 5;
}
set
{
num = value;
}
}
publicint num1
{
get
{
return 15;
}
set
{
num1 = value;
}
}
The code above will return 5 when the property when it is called from form1. To call the property from form1 we have to write the collowing code in form1.
int n = form2.num;
Example
Here br is object of form2 (browse form).
frmBrowse br = newfrmBrowse();
privatevoid btnBrowse_Click(object sender, EventArgs e)
{
br.ShowDialog();
txtId.Text = br.num;
txtName.Text = br.num1;
panel1.Enabled = true;
}
Here form2 in Browse form. When any cell is clicked in data grid of this form the record will be transferred from this form to Record form (i.e. Form1).
Anonymous User
27-Feb-2019Thanks for sharing it.
Samuel Fernandes
13-Jul-2017Keep sharing these types of articles,
It was really helpful to read this post.